//
//  PerfectContentTwoViewController.m
//  SHHCPhone
//
//  Created by sheng long on 14-6-18.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "PerfectContentTwoViewController.h"
#import "PerfectContentTwoView.h"
#import "PerfectContentThreeViewController.h"

@interface PerfectContentTwoViewController ()
{
    NSArray *viewArray;
}
@end

@implementation PerfectContentTwoViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    navigationBarView.title = @"完善资料";
    [navigationBarView setNormalLeftButton];
    
    NSArray *dataArray = nil;
    switch ([APP_USER_MSG.pregnancy integerValue]) {
        case 1:
        {
            //孕前
            dataArray = @[@"高龄产妇",@"家族疾病史",@"习惯性流产"];
        }
            break;
        case 2:
        {
            //孕中
            dataArray = @[@"血压高",@"血糖高",@"贫血"];
        }
            break;
        case 3:
        {
            //孕后
            dataArray = @[@"肥胖",@"血压高",@"血糖高"];
        }
            break;
        default:
            break;
    }

    CGFloat y = 0;
//    NSArray *dataArray = @[@"血压偏高",@"血脂偏高",@"血糖偏高",@"贫       血"];
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:1];
    for (int i = 0 ; i < dataArray.count; i++) {
        PerfectContentTwoView *view = [[PerfectContentTwoView alloc] initWithFrame:CGRectMake((CURRENT_CONTENT_WIDTH-220)/2, 27+50*i+NAVIGATIONBAR_HEIGHT, 220, 30)];
        [self.view addSubview:view];
        [view setContent:[dataArray objectAtIndex:i]];
        [view setSelected:NO];
        
        y=(view.frame.size.height+view.frame.origin.y);
        
        [array addObject:view];
    }
    viewArray = [[NSArray alloc] initWithArray:array];
    
    UIButton *button = [OftenMenthod setButtonTitle:@"确认"];
    [button setCenter:CGPointMake(CURRENT_CONTENT_WIDTH/2, y+50)];
    [button addTarget:self action:@selector(jumpButt) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

-(void)leftButtonClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)jumpButt
{
    [LoadingFrameView showLoadingview];
    CLog(@"跳过");
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:1];
    switch ([APP_USER_MSG.pregnancy integerValue]) {
        case 1:
        {
            //孕前
            [array addObject:@"older_monther"];
            [array addObject:@"family_disease"];
            [array addObject:@"habitual_abortion"];
        }
            break;
        case 2:
        {
            //孕中
            [array addObject:@"high_blood_pressure"];
            [array addObject:@"high_blood_sugar"];
            [array addObject:@"anaemia"];
        }
            break;
        case 3:
        {
            //孕后
            [array addObject:@"high_blood_fat"];
            [array addObject:@"high_blood_pressure"];
            [array addObject:@"high_blood_sugar"];
        }
            break;
        default:
            break;
    }
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:1];
    for (int i = 0 ; i < viewArray.count; i++) {
        [dic setObject:[NSNumber numberWithInt:((PerfectContentTwoView*)[viewArray objectAtIndex:i]).selected] forKey:[array objectAtIndex:i]];
    }
    [dic setValue:IOS_OTHERINFO forKeyPath:IOS_METHOD_NAME];
    [dic setValue:APP_USER_MSG.id forKey:@"id"];
    [self superASIStartAsynchronous:[NetUtls httpPost:self withValue:dic tag:IOS_OTHERINFOT_TAG need:YES]];
}

#pragma mark - ASIHTTPRequestDelegate
-(void)requestFinished:(ASIHTTPRequest *)request
{
    
}

-(void)requestFailed:(ASIHTTPRequest *)request
{
    CLog(@"%@===完善资料失败",[request responseString]);
    [LoadingFrameView autoDisappearTipview:@"完善资料失败"];
}

-(void)getASIRecordSucceed:(ASIHTTPRequest *)request data:(NSDictionary *)dic
{
    CLog(@"获取数据成功");
    NSMutableDictionary *d = [NSMutableDictionary dictionaryWithDictionary:dic];
    [d setValue:APP_USER_MSG.password forKey:@"password"];
    
    [AppDelegate getAppDelegate].userDic = d;
    
    UserMsg *msg = [[UserMsg alloc] init:d];
    APP_USER_MSG = msg;
    [LoadingFrameView directlyDisappear];
    PerfectContentThreeViewController *vc = [[PerfectContentThreeViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)getASIRecordFailed:(ASIHTTPRequest *)request data:(NSString *)failed
{
    CLog(@"%@===完善资料失败",failed);
    [LoadingFrameView autoDisappearTipview:failed];
}


@end
